#pragma once
#include <jni.h>
#include <boost\shared_ptr.hpp>
#include <boost\asio\serial_port.hpp>
#include <boost\asio\deadline_timer.hpp>
#include <boost\asio\streambuf.hpp>
#include <boost\thread\mutex.hpp>
#include "types.h"

typedef boost::shared_ptr<boost::unique_lock<boost::timed_mutex>> Lock;

class SerialPortInfo
{
private:
	serial_port_ptr pserial_port;
	boost::shared_ptr<boost::asio::deadline_timer> timer;
	bool read_time_out;
	boost::asio::streambuf stream;
	boost::timed_mutex  mutex;

public:
	SerialPortInfo(serial_port_ptr p, size_t buf_size);
	~SerialPortInfo();

	void timeout_handle(boost::shared_ptr<boost::asio::deadline_timer> t, boost::system::error_code e);
	void async_wait_timeout(JNIEnv *penv, jobject obj, int time);
	void cancel_async_wait(void);

	serial_port_ptr get_serial_port_ptr() { return pserial_port; }
	//boost::asio::deadline_timer& get_deadline_timer() { return timer; }
	boost::asio::streambuf& get_instream(){return stream;}

	Lock get_lock(JNIEnv* penv, jobject obj);
};

